Skip to content

Conversation

@rishikunnath2747
Copy link
Collaborator

@rishikunnath2747 rishikunnath2747 commented Nov 24, 2025

Currently during copying of attachments, custom properties and "Note" field doesn't get copied. This PR lets user copy these fields and ties the "Note" field to the cmis_description property in SDM

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist before requesting a review

  • I follow Java Development Guidelines for SAP
  • I have tested the functionality on my cloud environment.
  • I have provided sufficient automated/ unit tests for the code.
  • I have increased or maintained the test coverage.
  • I have ran integration tests on my cloud environment.
  • I have validated blackduck portal for any vulnerability after my commit.

Upload Screenshots/lists of the scenarios tested

Single tenant : https://github.com/cap-java/sdm/actions/runs/19707282786/job/56458047797
Mulit tenant : https://github.com/cap-java/sdm/actions/runs/19707297248/job/56508745431

  1. Copying attachment which has some custom properties assigned
  2. Copying attachment which has note field assigned
  3. Copying attachment which has both custom properties and note field assigned

@rishikunnath2747
Copy link
Collaborator Author

gemini please review

@vibhutikumar07
Copy link
Collaborator

gemini review

@github-actions
Copy link
Contributor

Gemini Automated Review
Summary of Changes
This Pull Request involves refactoring attachment handling logic, correcting error reporting mechanisms, addressing an incomplete service implementation, and updates to custom property extraction. While aiming for improvements, it introduces several potential bugs and significant issues related to test code cleanliness and API contract changes.

Best Practices Review 💡

  • Excessive Commented-Out Code: Large blocks of commented-out test code exist across SDMUpdateAttachmentsHandlerTest.java, SDMServiceImplTest.java, and SDMUtilsTest.java. This reduces readability, clutters the codebase, and masks potentially relevant tests.
  • Redundant Method: SDMCreateAttachmentsHandler.java contains a redundant method (updateDescriptionForCreate) whose logic is already covered by a more general utility.
  • Generic toString() for Custom Properties: The extractCustomProperties method in SDMCustomServiceHandler.java uses a generic value.toString() for all custom property values, which may not handle complex CMIS types (e.g., multi-valued properties, dates) correctly, leading to data loss or misinterpretation.
  • API Breaking Change: The prepareSecondaryProperties method in SDMUtils.java had its fileName parameter removed. This is an API breaking change that requires all call sites to be identified and updated.
  • Stray Comment Markers: Isolated // comment markers are present in SDMServiceImplTest.java without accompanying commented-out code, affecting code cleanliness.

Potential Bugs 🐛

  • Inconsistent 404 Error Reporting: In AttachmentsHandlerUtils.java, during an UPDATE operation, 404 errors report filenameInRequest instead of the more accurate fileNameInSDM (original filename).
  • Incomplete copyAttachment Implementation: The copyAttachment method in SDMServiceImpl.java was changed to return Map<String, String> but lacks the necessary logic to parse the HTTP response and construct this map, potentially leading to null returns or IOException without proper handling of a successful response.
  • Test Mock Signature Mismatch: In SDMCreateAttachmentsHandlerTest.java, the mock for sdmService.getObject returns a List<String>, which may not align with the actual sdmService.getObject method's signature or return contract, potentially causing runtime type mismatches.

Recommendations & Required Changes 🛠️

  1. Remove Redundant updateDescriptionForCreate Method

    • File: SDMCreateAttachmentsHandler.java
    • Description: The logic for updating the description property is already encapsulated in AttachmentsHandlerUtils.updateDescriptionProperty. The existing redundant method should be removed.
    • Recommended Code Snippet:
      // In SDMCreateAttachmentsHandler.java, inside processAttachment method:
      AttachmentsHandlerUtils.updateDescriptionProperty(
          null, // For create, descriptionInDB is effectively null
          descriptionInRequest,
          updatedSecondaryProperties);
      
      // Remove the private method:
      // private void updateDescriptionForCreate(...)
  2. Correct Filename Reporting for 404 Errors in UPDATE Operations

    • File: AttachmentsHandlerUtils.java
    • Description: For a 404 error during an UPDATE operation, the error report should reflect the original filename (fileNameInSDM) rather than the potentially modified filenameInRequest.
    • Recommended Code Snippet:
      // In AttachmentsHandlerUtils.java, inside handleSDMUpdateResponse method:
      case 404:
          filesNotFound.add(fileNameInSDM); // Use fileNameInSDM (original name) for 404
          revertAttachmentProperties(
              attachment,
              filenameInRequest, // This parameter is for the reversion logic, not the error list
              propertiesInDB,
              secondaryTypeProperties,
              descriptionInSDM);
          break;
  3. Complete copyAttachment Method Implementation

    • File: SDMServiceImpl.java
    • Description: The copyAttachment method's signature was changed, but the implementation for parsing the successful HTTP response and constructing the Map<String, String> is missing.
    • Recommended Code Snippet:
      // In SDMServiceImpl.java, inside copyAttachment method:
      // After `if (response.getStatusLine().getStatusCode() == 201) {`
      // The removed processing needs to be replaced. Assuming a similar structure to getObject, it might look like this:
      if (response.getStatusLine().getStatusCode() == 201) {
          String responseString = EntityUtils.toString(response.getEntity());
          JSONObject jsonObject = new JSONObject(responseString);
          JSONObject succinctProperties = jsonObject.getJSONObject("succinctProperties");
          Map<String, String> propertiesMap = new HashMap<>();
          // Example: populate map from response, adjust based on actual response structure
          propertiesMap.put("objectId", succinctProperties.optString("cmis:objectId", null));
          propertiesMap.put("filename", succinctProperties.optString("cmis:name", null));
          propertiesMap.put("description", succinctProperties.optString("cmis:description", null));
          // Add other custom properties based on 'customPropertiesInSDM'
          if (customPropertiesInSDM != null) {
              for (String prop : customPropertiesInSDM) {
                  propertiesMap.put(prop, succinctProperties.optString(prop, null));
              }
          }
          return propertiesMap;
      } else {
          // Handle other non-201 response codes, possibly throw ServiceException
          throw new IOException("Failed to copy attachment: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase() + " - " + responseBody);
      }
      // The previous 'return null;' or implicit null return should be replaced.
  4. Address Commented-Out Test Methods

    • Files: SDMUpdateAttachmentsHandlerTest.java, SDMServiceImplTest.java, SDMUtilsTest.java
    • Description: Many test methods are commented out. This significantly impacts test coverage and code clarity.
    • Action: Either uncomment and fix these tests to align with current logic and pass, or remove them entirely if they are no longer relevant or deprecated.
  5. Verify sdmService.getObject Method Contract

    • File: SDMCreateAttachmentsHandlerTest.java
    • Description: The mock for sdmService.getObject now returns List<String>. Confirm if the actual sdmService.getObject method has indeed changed its signature and update the service method implementation or the mock to ensure consistency.
  6. Improve Custom Property Type Handling

    • File: SDMCustomServiceHandler.java
    • Description: The extractCustomProperties method's reliance on value.toString() for all custom property types is brittle.
    • Action: Implement more explicit type checking and handling (e.g., for dates, numbers, booleans, multi-valued properties) to ensure data integrity and correct representation.
  7. Update All Call Sites for prepareSecondaryProperties

    • File: SDMUtils.java (and all dependent modules/callers)
    • Description: The fileName parameter was removed from prepareSecondaryProperties.
    • Action: Identify all places where prepareSecondaryProperties is called and update them to pass the fileName within the secondaryProperties map as the new signature expects.
  8. Remove Stray Comment Markers

    • File: SDMServiceImplTest.java
    • Description: Remove isolated // comment markers on lines 1299 and 1342 that do not comment out any code.
    • Recommended Code Snippet:
      --- a/sdm/src/test/java/unit/com/sap/cds/sdm/service/SDMServiceImplTest.java
      +++ b/sdm/src/test/java/unit/com/sap/cds/sdm/service/SDMServiceImplTest.java
      @@ -1296,7 +1296,6 @@ public void testValidSecondaryPropertiesFail() throws IOException {
           Cache<SecondaryPropertiesKey, List<String>> mockCache = Mockito.mock(Cache.class);
           Mockito.when(mockCache.get(any())).thenReturn(null);
       
      -      //
           cacheConfigMockedStatic.when(CacheConfig::getSecondaryPropertiesCache).thenReturn(mockCache);
           String grantType = "TOKEN_EXCHANGE";
           when(tokenHandler.getHttpClient(any(), any(), any(), eq(grantType))).thenReturn(httpClient);
      @@ -1339,7 +1338,6 @@ public void testValidSecondaryPropertiesFailEmptyResponse() throws IOException {
           Cache<SecondaryPropertiesKey, List<String>> mockCache = Mockito.mock(Cache.class);
           Mockito.when(mockCache.get(any())).thenReturn(secondaryTypesCached);
       
      -      //
           cacheConfigMockedStatic.when(CacheConfig::getSecondaryPropertiesCache).thenReturn(mockCache);
           cacheConfigMockedStatic.when(CacheConfig::getSecondaryTypesCache).thenReturn(mockCache);
       

Quality Rating
6/10

Overall Assessment
The current state of the code requires substantial work before it can be considered ready for merge. There are several critical bugs, including an incomplete core service method (copyAttachment) that could lead to runtime errors or incorrect behavior. Additionally, the widespread presence of commented-out tests significantly reduces confidence in the test coverage and overall stability. The API breaking change in SDMUtils needs careful coordination across all consuming modules. All identified potential bugs and best practice violations must be addressed, and the test suite should be fully restored and passing to ensure the integrity and reliability of the application.

@rishikunnath2747
Copy link
Collaborator Author

Relevant issues raised by gemini are addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants